package org.neu.onlineparadise.controller;



import org.neu.onlineparadise.Result.Result;
import org.neu.onlineparadise.utils.AliOssUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

@RestController
public class FileUploadController {
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws Exception {
        String oringinalFilename = file.getOriginalFilename();

        String filename = UUID.randomUUID().toString() + oringinalFilename.substring(oringinalFilename.lastIndexOf("."));
        String url =AliOssUtil.uploadFile(filename, file.getInputStream());
        return Result.success(url);
    }
}
